Skip to content

refactor: deduplicate interpolator precompute and code4 matrix construction#2713

Open
henryiii wants to merge 1 commit into
mainfrom
refactor/interpolator-dedup
Open

refactor: deduplicate interpolator precompute and code4 matrix construction#2713
henryiii wants to merge 1 commit into
mainfrom
refactor/interpolator-dedup

Conversation

@henryiii

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Part of the code review in #2706.

Summary

Deduplicates repeated code in src/pyhf/interpolators/:

  • code1.py and code4.py: the bases_up/bases_dn/mask_on/mask_off (plus ones in code4) block was duplicated verbatim between _precompute and _precompute_alphasets. Extracted into a private _precompute_alphaset_dependent() helper called by both, keeping _precompute's extra histogram-only setup. Removed the redundant bare return statements at the ends of _precompute_alphasets.
  • code4.py: the six-row A_inverse matrix literal appeared twice — once in code4.__init__ and once inside _slow_code4.product, where it was rebuilt on every scalar call. Factored it into a module-level _a_inverse(alpha0) function returning the nested list, used by both. In _slow_code4 it is now computed once per instance (alpha0 is fixed at construction) instead of per call.

Same math, same shapes, no behavior change.

Test plan

All run against the dev environment (strict pytest, filterwarnings=error), all backends:

  • pytest tests/test_interpolate.py -q → 69 passed (includes slow-path vs fast-path agreement tests)
  • pytest tests/test_validation.py tests/test_regression.py -q → 26 passed
  • prek -a (lint/format) → clean

🤖 Generated with Claude Code

…uction

Factor the shared alphaset-dependent precompute block in code1 and code4
into a private _precompute_alphaset_dependent helper called by both
_precompute and _precompute_alphasets, and drop the redundant bare returns.

Factor the rank-6 A_inverse matrix literal (previously duplicated in
code4.__init__ and rebuilt on every scalar call in _slow_code4.product)
into a module-level _a_inverse(alpha0) helper, computed once per instance
in _slow_code4.

No change to math, shapes, or behavior.

Assisted-by: ClaudeCode:claude-opus-4.8
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@henryiii, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 29 minutes and 55 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 081af9d1-195f-43ef-93b8-58d17291390d

📥 Commits

Reviewing files that changed from the base of the PR and between 0e54a51 and fa8c088.

📒 Files selected for processing (2)
  • src/pyhf/interpolators/code1.py
  • src/pyhf/interpolators/code4.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@henryiii henryiii marked this pull request as ready for review June 12, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant